/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.hutech09.jsale.web.manager.users;

import java.util.List;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import org.hutech09.jsale.bsn.IAccessUserManager;
import org.hutech09.jsale.entity.AccessUser;
import org.primefaces.event.SelectEvent;

/**
 *
 * @author Nam
 */
@ManagedBean
@RequestScoped
public class BrowseAccessUserCtrl {

    private static final Logger LOG = Logger.getLogger(BrowseAccessUserCtrl.class.getName());

    @ManagedProperty("#{groupUserInCtrl}")
    private GroupUserInCtrl groupCtrl;

    @EJB
    private IAccessUserManager userManager;

    private AccessUser selectedUser;

    private UserDataModel dataModel;

    public BrowseAccessUserCtrl() {
    }

    public void onRowSelect(SelectEvent event) {
        groupCtrl.setUser(selectedUser);
    }

    public AccessUser getSelectedUser() {
        return selectedUser;
    }

    public void setSelectedUser(AccessUser selectedUser) {
        this.selectedUser = selectedUser;
    }

    public IAccessUserManager getUserManager() {
        return userManager;
    }

    public void setUserManager(IAccessUserManager userManager) {
        this.userManager = userManager;
    }

    public UserDataModel getDataModel() {
        if (dataModel == null) {
            List<AccessUser> users = userManager.getAllUser();
            System.out.println(users);
            dataModel = new UserDataModel(users);
        }
        return dataModel;
    }

    public void setDataModel(UserDataModel dataModel) {
        this.dataModel = dataModel;
    }

    public GroupUserInCtrl getGroupCtrl() {
        return groupCtrl;
    }

    public void setGroupCtrl(GroupUserInCtrl groupCtrl) {
        this.groupCtrl = groupCtrl;
    }
}
